package org.example;

/**
 * 描述：     使用刚才自己写的UncaughtExceptionHandler
 */
public class UseOwnUncaughtExceptionHandler implements Runnable {

    public static void main(String[] args) throws InterruptedException {
//        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler("捕获器main工作了"));

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("开始进入ziThread-0线程了");
                Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler("捕获器ziThread-0工作了"));
//                while (true) {
//
//                }
                System.out.println("退出了ziThread-0线程了");
            }
        }).start();

        Thread.sleep(1000);

        new Thread(new UseOwnUncaughtExceptionHandler(), "MyThread-1").start();
        Thread.sleep(300);

        System.out.println("main线程正常执行完毕");
    }


    @Override
    public void run() {
        int i = 1 / 0;
        System.out.println("i的结果是" + i);
    }
}
